'use strict';
app.service('shopTemplateService',['$q','utilService',function($q,utilService){
    var _this_=this;
    //添加属性参数
    _this_.add=function($scope){

        var shopTemplateAddVO=[];
        for(var i=0;i<$scope.templates.length;i++){
            var obj=new Object();
            obj.type=$scope.templates[i].type;
            obj.typography=$scope.templates[i].typography;
            obj.sort=i;
            if($scope.templates[i].advertise.length>0){
                obj.shopTemplateAdvertise=JSON.stringify($scope.templates[i].advertise);
            }
            if($scope.templates[i].navigation.length>0){
                obj.shopTemplateNavigation=JSON.stringify($scope.templates[i].navigation);
            }
            if($scope.templates[i].goods.length>0){
                obj.shopTemplateGoods=JSON.stringify($scope.templates[i].goods);
            }
            shopTemplateAddVO.push(obj);
        }

        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain+"shop/template",
            data:{shopTemplateAddVO:shopTemplateAddVO}
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }

}]);